package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// LocationTag 位置标签
type LocationTag struct {
	ID         string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键id"`
	Name       string `json:"name" gorm:"column:name;type:string;size:50;not null;comment:标签名称"`
	MerchantID string `json:"merchant_id" gorm:"column:merchant_id;type:string;size:30;not null;comment:商户id"`
	CreatedAt  int64  `json:"-" gorm:"column:created_at;autoCreateTime;type:int;size:64;comment:创建时间"`
	UpdatedAt  int64  `json:"-" gorm:"column:updated_at;autoUpdateTime;type:int;size:64;comment:更新时间"`
}

// TableName 表名
func (LocationTag) TableName() string {
	return "location_tag"
}

// BeforeCreate 自增id
func (l *LocationTag) BeforeCreate(tx *gorm.DB) (err error) {
	if l.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	l.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &LocationTag{})
}
